package com.gc.server.controller;

import java.util.HashMap;
import java.util.List;

import com.gc.server.enums.LevelEnum;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import java.util.Map;
import com.yf.consts.DaoConst;
import com.gc.server.entity.LevelEntity;
import com.gc.server.service.LevelService;
import com.yf.response.R;


/**
 * 级别Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Tue Mar 10 11:17:45 CST 2020
 */
@RestController
@RequestMapping("/level")
public class LevelController {
    @Autowired
    private LevelService levelService;

    /**
     * 列表级别
     */
    @RequestMapping("/list")
    @RequiresPermissions("level:list")
    public R list(@RequestParam Map<String,Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<LevelEntity> levelList = levelService.queryList(params);
        return R.ok(new PageInfo(levelList));
    }

    /**
     * 查看级别
     */
    @SysLog("查看级别")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("level:info")
    public R info(@PathVariable("id") Long id) {
        LevelEntity level = levelService.get(id);

        return R.ok(level);
    }

    /**
     * 保存级别
     */
    @SysLog("保存级别")
    @RequestMapping("/save")
    @RequiresPermissions("level:save")
    public R save(LevelEntity level) {
        levelService.save(level);

        return R.ok(level);
    }

    /**
     * 修改级别
     */
    @SysLog("修改级别")
    @RequestMapping("/update")
    @RequiresPermissions("level:update")
    public R update(LevelEntity level) {
        levelService.update(level);

        return R.ok(level);
    }

    /**
     * 删除级别
     */
    @SysLog("删除级别")
    @RequestMapping("/delete")
    @RequiresPermissions("level:delete")
    public R delete(Long[]ids) {
        levelService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有级别
     */
    @SysLog("所有级别")
    @RequestMapping("/queryAll")
    public R queryAll (@RequestParam Map<String,Object> params) {

        List<LevelEntity> levelList = levelService.queryList(params);

        return R.ok(levelList);
    }

    /**
     * 所有enums
     */
    @SysLog("所有enums")
    @RequestMapping("/dmz/options")
    public R options() {
        HashMap<String,Object> options = new HashMap();
        options.put("levelOptions", LevelEnum.names());
        return R.ok(options);
    }


    /***********自定义开始***********/
}
